/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.market.web;

import java.io.IOException;
import javax.annotation.security.RolesAllowed;
import javax.xml.registry.infomodel.User;
import org.glassfish.sse.api.*;

/**
 *
 * @author project
 */

@ServerSentEvent("/chatroom")
public class ChatConnection extends ServerSentEventHandler {

    
    @Override
    public void onConnected(ServerSentEventConnection connection) {
        super.onConnected(connection); 
        System.out.println("------> new connection");
    }
    
   
  
    public void send(ServerSentEventData data) {
        try {
            connection.sendMessage(data);
        } catch (IOException ex) {
            connection.close();
        }
    }
    
   
    public void send(String msg) {
        try {
            connection.sendMessage(msg);
        } catch (IOException ex) {
            connection.close();
        }
    }
    
}
